package com.ruoyi.web.controller.survey;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.survey.SurveyInfo;
import com.ruoyi.system.service.survey.ISurveyInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 问卷信息，存储问卷的基本信息，包括ID、标题、描述和时间戳Controller
 * 
 * @author ruoyi
 * @date 2024-11-25
 */
@RestController
@RequestMapping("/survey/surveyInfo")
public class SurveyInfoController extends BaseController
{
    @Autowired
    private ISurveyInfoService surveyInfoService;

    /**
     * 查询问卷信息，存储问卷的基本信息，包括ID、标题、描述和时间戳列表
     */
    @PreAuthorize("@ss.hasPermi('survey:surveyInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurveyInfo surveyInfo)
    {
        startPage();
        List<SurveyInfo> list = surveyInfoService.selectSurveyInfoList(surveyInfo);
        return getDataTable(list);
    }

    /**
     * 导出问卷信息，存储问卷的基本信息，包括ID、标题、描述和时间戳列表
     */
    @PreAuthorize("@ss.hasPermi('survey:surveyInfo:export')")
    @Log(title = "问卷信息，存储问卷的基本信息，包括ID、标题、描述和时间戳", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurveyInfo surveyInfo)
    {
        List<SurveyInfo> list = surveyInfoService.selectSurveyInfoList(surveyInfo);
        ExcelUtil<SurveyInfo> util = new ExcelUtil<SurveyInfo>(SurveyInfo.class);
        util.exportExcel(response, list, "问卷信息，存储问卷的基本信息，包括ID、标题、描述和时间戳数据");
    }

    /**
     * 获取问卷信息，存储问卷的基本信息，包括ID、标题、描述和时间戳详细信息
     */
    @PreAuthorize("@ss.hasPermi('survey:surveyInfo:query')")
    @GetMapping(value = "/{surveyId}")
    public AjaxResult getInfo(@PathVariable("surveyId") Long surveyId)
    {
        return success(surveyInfoService.selectSurveyInfoBySurveyId(surveyId));
    }

    /**
     * 新增问卷信息，存储问卷的基本信息，包括ID、标题、描述和时间戳
     */
    @PreAuthorize("@ss.hasPermi('survey:surveyInfo:add')")
    @Log(title = "问卷信息，存储问卷的基本信息，包括ID、标题、描述和时间戳", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurveyInfo surveyInfo)
    {
        return toAjax(surveyInfoService.insertSurveyInfo(surveyInfo));
    }

    /**
     * 修改问卷信息，存储问卷的基本信息，包括ID、标题、描述和时间戳
     */
    @PreAuthorize("@ss.hasPermi('survey:surveyInfo:edit')")
    @Log(title = "问卷信息，存储问卷的基本信息，包括ID、标题、描述和时间戳", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurveyInfo surveyInfo)
    {
        return toAjax(surveyInfoService.updateSurveyInfo(surveyInfo));
    }

    /**
     * 删除问卷信息，存储问卷的基本信息，包括ID、标题、描述和时间戳
     */
    @PreAuthorize("@ss.hasPermi('survey:surveyInfo:remove')")
    @Log(title = "问卷信息，存储问卷的基本信息，包括ID、标题、描述和时间戳", businessType = BusinessType.DELETE)
	@DeleteMapping("/{surveyIds}")
    public AjaxResult remove(@PathVariable Long[] surveyIds)
    {
        return toAjax(surveyInfoService.deleteSurveyInfoBySurveyIds(surveyIds));
    }
}
